package com.axjy.service.impl;

import com.axjy.dao.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.axjy.util.Pager;
import com.axjy.web.dto.UserDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * Created by asus on 2018/1/11.
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService{

    @Resource
   private UserMapper userMapper;

    @Override
    public Pager searchPager(Integer offset, Integer limit, UserDto dto) {
       Pager pager=new Pager();
       pager.setTotal(userMapper.searchTotal(dto));
        pager.setRows(userMapper.searchRows(offset,limit,dto));
        return pager;
    }

    @Override
    public void updateRole(Integer userId, Integer roleId) {
        userMapper.updateByRoleId(userId,roleId);
    }

    @Override
    public User login(String name, String pwd) {
        return userMapper.login(name,pwd);
    }

    @Override
    public void add(User user) {
        user.setModifyTime(LocalDateTime.now());
        user.setStatus(1);
        user.setPwd("123456");
    }
}
